package com.etc.service.impl;

import com.etc.dao.impl.AdminDaoImpl;
import com.etc.entity.Admins;
import com.etc.service.IAdminService;
import com.etc.util.MD5Util;

public class AdminServiceImpl implements IAdminService{
	AdminDaoImpl dao = new AdminDaoImpl();

	@Override
	public Admins queryAdminByName(String adminName, String adminPwd) {
		//service层进行md5加密
		adminPwd=MD5Util.doubleEncryption(adminPwd);
		return dao.queryAdminByName(adminName, adminPwd);
	}

	@Override
	public boolean addAdmin(Admins admin) {
		//获得当前对象密码
		String adminPwd = admin.getAdminPwd();
		//md5加密密码
		adminPwd = MD5Util.doubleEncryption(adminPwd);
		admin.setAdminPwd(adminPwd);
		//传到数据库的是加密后的密码
		return dao.addAdmin(admin);
	}

	@Override
	public boolean removeAdmin(String adminName, String adminPwd) {
		// TODO Auto-generated method stub

		adminPwd = MD5Util.doubleEncryption(adminPwd);
		Admins admin = dao.queryAdminByName(adminName, adminPwd);
		if (admin==null) {
			return false;
		} 
		//修改管理员状态为0,即注销
		admin.setAdminStatus(0);
		System.out.println("123"+admin);
		return dao.changeAdminInfo(admin);
	}

	@Override
	public boolean changeAdminPwd(Admins admin, String newPwd) {
		//将新密码加密
		String newAdminPwd = MD5Util.doubleEncryption(newPwd);
		//给admin重设新密码
		admin.setAdminPwd(newAdminPwd);
		//更改管理员信息
		boolean flag = dao.changeAdminInfo(admin);
		return flag;
	}

	/**
	 * 修改管理员头像
	 * admin:管理员对象
	 * return:boolean值
	 */
	@Override
	public boolean modifAdminPic(Admins admin) {
		return dao.modifAdminPic(admin);
	}


}
